<?php
require_once("inc.member.php");

$this_title="$vars[member_title] &raquo; ".__("Group Sales History");
$page_title=__("Group Sales History");
$content_title=__("Group Sales History");

$item_per_page=$vars["user_item_per_page"];
$td_width=180;

			$comm_query = true;

			$count_sql="select count(*) from $db->member_comm_sum where uid='$uid' order by cdate";
			$record_sql="select * from $db->member_comm_sum where uid='$uid' order by cdate limit <%limit_start%>, <%limit%>";
			
			$cur_page=$_GET["nav"];
			$total_record=@mysql_result(mysql_query($count_sql), 0);
			$total_page=ceil($total_record/$item_per_page);
			if($cur_page=="") $cur_page=$total_page;
			$page=($cur_page? ($cur_page>$total_page? $total_page : ($cur_page<1? 1 : $cur_page)) : 1);
			$limit_start=($page-1)*$item_per_page;
			$nav_link=format_page($page, $total_page, 15);
			$this_page_total=@mysql_num_rows($r=mysql_query(str_replace("<%limit_start%>", $limit_start, str_replace("<%limit%>", $item_per_page, $record_sql))));
			$grand_total = @mysql_result(mysql_query($sum_sql), 0) or 0;
			$k=0;
			for($i=0;$i<$this_page_total;$i++){
				$comm=mysql_fetch_assoc($r);
				$this_no = ($page - 1) * $item_per_page + $i + 1;
				/*
				$lcf = 0;
				$rcf = 0;	
				if($comm['pbv']==0 || $comm['pbv']==$comm['pgs']){
					$lcf = $comm['lcf'] + $comm['pbv'];
					$rcf = $comm['rcf'] + $comm['pbv'];
				}else{		
					if(($comm['pbv']*2)<>$comm['pgs'] && $comm['pgs']>0){
						if($lcf>$rcf){
							$lcf = $comm['lcf'] + $comm['pgs'] - $comm['pbv'];
							$rcf = $comm['rcf'] + $comm['pbv'];
						}else{
							$lcf = $comm['lcf'] + $comm['pbv'];
							$rcf = $comm['rcf'] + $comm['pgs'] - $comm['pbv'];
						}
					}else{
						$lcf = $comm['lcf'] + $comm['pbv'];
						$rcf = $comm['rcf'] + $comm['pbv'];
					}
				}
				*/
				$personal_sales = @mysql_result(mysql_query("select sum(total_bv) from $db->purchase where uid='$uid' and date_format(cdate, '%Y-%m-%d')='".$comm['bonus_date']."'"), 0);
				
				$lcf = $comm['lcf'] + $comm['pbv'];
				$rcf = $comm['rcf'] + $comm['pbv'];
				
				$comm_row.="
					<tr class='row$k'>
						<td class='left'>".$comm['bonus_date']."</td>
						<td class='right'>".number_format($comm['pgs']-$personal_sales,2)."</td>
						<td class='right'>".number_format($lcf,2)."</td>
						<td class='right'>".number_format($rcf,2)."</td>
						<td class='right'>".number_format($comm['pbv'],2)."</td>
					</tr>";
				$k=1-$k;
			}

			//listing text
			$listing_text=replace_tag(__("Listing <%x%> <%comm%>."), array("<%x%>"=>strval($total_record), "<%comm%>"=>$total_record>1? __("records") : __("record")));

			//comm header
			$header_row = "
				<tr class='pbl_header'>
					<td>".__("Date")."</td>
					<td>".__("Group Sales")."</td>
					<td>".__("Left Group Sales")."</td>
					<td>".__("Right Group Sales")."</td>
					<td>".__("Pairing Amount")."</td>		
				</tr>";
			
			//listing
			$comm_list=
			"
			$listing_text<br>$nav_link
			<table class='pbl_table'>
				$header_row
				$comm_row
			</table>";


	$errmsg=$errmsg? format_err(__("There is some error(s), please correct them before continuing:")."<br />\n<br />\n$errmsg") : "";

//#####END COMMISSION GET#####


//$content="<h2>$page_title</h2>$upload_ui$comm_list";
$content=$comm_list;

print format_member_page($content, $this_title, $content_title, $css.$jvscript);
?>